Repository navigation
fix(cold-store-reaper): rebuild turso dumps with repeated tables and vector indexes - #12028
Conversation
…vector indexes libsql's /dump of the atlas database emits the vector table vec_snowflake_m_v2_768_f32 twice, byte for byte, so the sqlite3 rebuild stopped on the second copy's first primary key. Its last statement also creates a libsql_vector_idx index, which stock sqlite3 cannot run. dedupe_dump.py drops a repeated table block only when its CREATE and every row match the first copy (sha256 and count), and fails the export when they differ. vector_index_dump.py records each libsql vector index statement in cold_store_libsql_vector_indexes instead of running it; the index data stays in its shadow tables. Refs #12000 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Caution Review failedThe pull request is closed.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d8780735c0
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| block = original = None | ||
| match = CREATE.match(line) |
There was a problem hiding this comment.
Track SQL literal context before dropping repeated CREATEs
When a multiline text value contains a line identical to an earlier empty table's CREATE statement, this physical-line match mistakes the text for a repeated table block. For example, after CREATE TABLE IF NOT EXISTS empty (x);, a later INSERT INTO notes VALUES('before\nCREATE TABLE IF NOT EXISTS empty (x);\nafter'); loses the embedded CREATE line: both apparent empty-table blocks have matching zero-row digests. The resulting INSERT remains valid, so the export passes COMMIT and integrity checks while silently corrupting the stored text. Track statement/string-literal context before recognizing table blocks; the new vector-index filter needs the same protection before rewriting physical lines.
Useful? React with 👍 / 👎.
| def main(): | ||
| out = sys.stdout.buffer | ||
| created = False | ||
| for line in sys.stdin.buffer: |
There was a problem hiding this comment.
Reject unexpected arguments before processing either filter
Both new scripts enter their stdin-processing loops without inspecting command-line arguments, so an invocation with an unknown flag or stray positional silently performs the transformation and exits successfully rather than reporting a usage error. This violates the operator-script argument contract in AGENTS.md, which requires strict argument validation before output or other effects. Declare that these filters accept no arguments and reject unexpected arguments with a nonzero exit before consuming stdin or writing stdout.
AGENTS.md reference: AGENTS.md:L47-L51
Useful? React with 👍 / 👎.
| import sys | ||
|
|
||
| CREATE = re.compile( | ||
| rb'^CREATE TABLE (?:IF NOT EXISTS )?("(?:[^"]|"")+"|\'(?:[^\']|\'\')+\'|[A-Za-z_][A-Za-z0-9_]*)' |
There was a problem hiding this comment.
Match complete identifiers before comparing table definitions
For valid unquoted SQLite identifiers containing $ or non-ASCII characters, this regex captures only the ASCII prefix without checking that the identifier ends there. Distinct declarations such as CREATE TABLE IF NOT EXISTS foo$one(x); and CREATE TABLE IF NOT EXISTS foo$two(y); are therefore both recorded as table foo. The second declaration triggers the differing-definition error and aborts an otherwise valid export even though there is no repeated table; these declarations passed through the previous pipeline unchanged. Match the complete identifier, or leave unsupported identifier forms untouched rather than registering a partial name.
Useful? React with 👍 / 👎.
Before: the nightly Turso export of the atlas database failed every night. libsql's
/dumpemits the vector tablevec_snowflake_m_v2_768_f32twice, byte for byte, so the sqlite3 rebuild stopped on the second copy's first primary key. Past that, the dump's last statement creates alibsql_vector_idxindex, which stock sqlite3 can't run.After: the atlas export rebuilds into a clean SQLite file. The repeated table copy is dropped (only when it matches the first copy exactly) and the vector index statement is kept as a row in
cold_store_libsql_vector_indexes; the index data itself stays in its shadow tables.How:
scripts/dedupe_dump.pystreams the dump with constant memory. For each table it keeps a sha256 and count of its first block's INSERT lines; a secondCREATE TABLEfor the same table must have an identical definition, and its rows' hash and count must match, or the export fails (no row is ever dropped silently).scripts/vector_index_dump.pyreplaces each single-lineCREATE INDEX ... (libsql_vector_idx(...))with an INSERT intocold_store_libsql_vector_indexes(name, sql). To restore into libsql, drop the index's shadow table and itslibsql_vector_meta_shadowrow, then run the recorded statement.export-turso.shpipesrepair_dump.py | dedupe_dump.py | vector_index_dump.py.Tested on the live atlas dump (13.5 GB, read-only token, Nov 19): the filter dropped one repeated copy of 107,639 identical rows, the rebuild passed
integrity_check, the vec table has 107,639 distinctchunk_ids, all 14 user tables are present, and the file is 7.3 GB (about 3.6 GB gzipped). Unit tests: 47 pass across the dedupe, vector-index, export, repair and nightly suites.Refs #12000
Generated by Claude Code
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.